public class test {
    // 星辰能量Ⅰ(⭐⭐)
    public class Main {
        //随从数
        public static int n;
        //方案数
        public static int sum;
        public static int[] nums;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            //在此输入您的代码...
            int t = in.nextInt();
            while(t-- > 0){
                n = in.nextInt();
                nums = new int[n];
                for(int i = 0;i < n;i++){
                    nums[i] = in.nextInt();
                }
                dfs(5);
                System.out.println(sum);
                sum = 0;
            }
            in.close();
        }
        //num -> 此时的星辰能量
        public static void dfs(int num){
            int c = 0;
            for(int i = 0;i < n;i++){
                //记录被干掉的随从数量
                if(nums[i] <= 0){
                    c++;
                }
            }
            if(c == n){
                sum++;
                return;
            }
            //此时星辰能量燃尽了!没办法了呀!
            if(num == 0){
                return;
            }
            for(int i = 0;i < n;i++){
                if(nums[i] > 0){
                    nums[i] -= num;
                    dfs(num - 1);
                    nums[i] += num;
                }
            }
        }
    }
    //dfs实现组合类枚举(⭐⭐)
    public class Main1 {
        public static List<Integer> path;
        public static boolean[] count;
        public static int n;
        public static int num;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            //在此输入您的代码...
            num = in.nextInt();
            n = in.nextInt();
            path = new ArrayList<>();
            count = new boolean[n + 500];
            dfs(1);
            in.close();
        }
        public static void dfs(int index) {
            if (path.size() == n) {
                for (int i = 0; i < n; i++) {
                    System.out.print(path.get(i) + " ");
                }
                System.out.println();
                return;
            }
            for(int i = index;i <= num;i++) {
                if (!count[i]) {
                    path.add(i);
                    count[i] = true;
                    dfs(i + 1);
                    path.remove(path.size() - 1);
                    count[i] = false;
                }
            }
        }
    }
    
}
